home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue49 / Build / incver.dpr < prev    next >
Encoding:
Text File  |  1999-03-20  |  1.6 KB  |  69 lines

  1. {$APPTYPE CONSOLE}
  2. {$H+,O+}
  3.  
  4. program IncVer;
  5.  
  6. uses
  7.   Windows,
  8.   SysUtils,
  9.   IniFiles;
  10.  
  11.   function PosR(subs, s: string): integer;
  12.   var
  13.     i: integer;
  14.     ls: integer;
  15.   begin
  16.     ls := Length(subs);
  17.     if ls <= Length(s) then
  18.     begin
  19.       for i := Length(s)-ls+1 downto 1 do
  20.       begin
  21.         if Copy(s,i,ls) = subs then
  22.         begin
  23.           PosR := i;
  24.           Exit;
  25.         end;
  26.       end;
  27.     end;
  28.     PosR := 0;
  29.   end; { PosR }
  30.  
  31.   procedure IncVersion(dofFile: string);
  32.   var
  33.     ini   : TINIFile;
  34.     sBuild: string;
  35.     p     : integer;
  36.   begin
  37.     if Pos('\',dofFile) = 0 then dofFile := '.\'+dofFile; // stupid TIniFile opens file in windows dir by default!
  38.     if not FileExists(dofFile) then begin
  39.       Writeln('IncrementVersion 1.0');
  40.       Writeln('file ',dofFile,' does not exist!');
  41.       Halt(1);
  42.     end;
  43.     ini := TIniFile.Create(dofFile);
  44.     try
  45.       Ini.WriteInteger('Version Info','Build',Ini.ReadInteger('Version Info','Build',-1)+1);
  46.       sBuild := Ini.ReadString('Version Info Keys','FileVersion','');
  47.       if sBuild <> '' then begin
  48.         p := PosR('.',sBuild);
  49.         if p > 0 then
  50.           sBuild := Copy(sBuild,1,p) +
  51.                     IntToStr(StrToIntDef(Copy(sBuild,p+1,Length(sBuild)-p),-1)+1);
  52.         Ini.WriteString('Version Info Keys','FileVersion',sBuild);
  53.       end;
  54.     finally ini.free; end;
  55.   end; { IncVersion }
  56.  
  57.   procedure Usage;
  58.   begin
  59.     Writeln('IncrementVersion 1.0');
  60.     Writeln('Usage: incver dof_file');
  61.     Halt(1);
  62.   end; { Usage }
  63.  
  64. begin
  65.   if ParamCount <> 1 then Usage;
  66.   IncVersion(ParamStr(1));
  67. end.
  68.  
  69.